using System.Collections;
using System.Collections.Generic;
using ResourceFrame;
using UnityEngine;
using UnityEngine.UI;

public class TestGameObject : MonoBehaviour
{
    public Image image;
    public Button buttonLoad;
    public Button buttonUnLoad;
    public GameObject loadObj;
    void Start()
    {
        _ = YooAssetHelper.Instance;
        buttonLoad.onClick.AddListener(OnClickLoad);
        buttonUnLoad.onClick.AddListener(OnClickUnLoad);
    }

    public void OnClickLoad()
    {
        ResManager.Instance.LoadAssetAsync<Sprite>("caixukun", image.gameObject, (sprite) =>
        {
            image.sprite = sprite;
        });
        
        ResManager.Instance.LoadAssetAsync<GameObject>("Prefab1", loadObj.gameObject, (p1) =>
        {
            GameObject.Instantiate(p1,loadObj.transform,false);
        });
        
        ResManager.Instance.LoadAssetAsync<GameObject>("Prefab2", loadObj.gameObject, (p2) =>
        {
            GameObject.Instantiate(p2,loadObj.transform,false);
        });
        
        ResManager.Instance.LoadAssetAsync<GameObject>("Prefab3", loadObj.gameObject, (p3) =>
        {
            GameObject.Instantiate(p3,loadObj.transform,false);
        });
    }
    
    public async void OnClickUnLoad()
    {
        GameObject.Destroy(image.gameObject);
        GameObject.Destroy(loadObj);
        await ResManager.Instance.UnloadAsset();
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
